import * as echarts from "echarts"
import { getViewPortHeight } from "@/util/tools"
const divHeight = getViewPortHeight() - 100
export const initChart = async ({ label, value }) => {
  // const myChart = echarts.getInstanceByDom(domRef)
  const divBox = document.getElementById("chartId")
  // divBox.
  const myChart = echarts.init(divBox)

  //   const legendData = ["终端设备检测电流", "实际电流"] //图例
  const option = {
    xAxis: {
      boundaryGap: false,
      type: "category",
      data: label
    },
    yAxis: {
      type: "value"
    },
    series: [
      {
        data: value,
        type: "line"
      }
    ]
  }

  myChart.setOption(option)

  // 监听窗口变化，响应图表
  window.addEventListener("resize", function () {
    if (myChart) {
      myChart.resize()
    }
  })

  return {
    resize: function () {
      myChart.resize()
    }
  }
}
